<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册 - 网络五子棋对战游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            color: white;
        }
        
        .nav {
            width: 100%;
            padding: 20px;
            text-align: center;
            font-size: 1.8rem;
            font-weight: bold;
            background: rgba(0, 0, 0, 0.2);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .login-container {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
        }
        
        .login-dialog {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 40px;
            width: 400px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .login-dialog h3 {
            text-align: center;
            margin-bottom: 30px;
            font-size: 1.8rem;
        }
        
        .row {
            margin-bottom: 20px;
        }
        
        .row span {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        .row input {
            width: 100%;
            padding: 12px 15px;
            border: none;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.9);
            font-size: 1rem;
            transition: all 0.3s ease;
        }
        
        .row input:focus {
            outline: none;
            box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
        }
        
        #submit {
            width: 100%;
            padding: 12px;
            background: linear-gradient(45deg, #ff8a00, #e52e71);
            border: none;
            border-radius: 8px;
            color: white;
            font-size: 1.1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
        }
        
        #submit:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }
        
        .login-link {
            text-align: center;
            margin-top: 20px;
        }
        
        .login-link a {
            color: #ffcc00;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .login-link a:hover {
            color: #ffdd44;
            text-decoration: underline;
        }
        
        .back-home {
            position: absolute;
            top: 30px;
            left: 30px;
            color: white;
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: all 0.3s;
        }
        
        .back-home:hover {
            transform: translateX(-5px);
        }
    </style>
</head>
<body>
    <a href="/" class="back-home">
        <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
            <path d="M11.5 14.5L5 8l6.5-6.5L12 0l-8 8 8 8 1.5-1.5z"/>
        </svg>
        返回首页
    </a>
    
    <div class="nav">网络五子棋对战游戏</div>
    <div class="login-container">
        <div class="login-dialog">
            <h3>注册</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">
            </div>
            <div class="row">
                <button id="submit" onclick="register()">注册</button>
            </div>
            <div class="login-link">
                已有账号？<a href="/login.html">立即登录</a>
            </div>
        </div>
    </div>

    <script src="js/jquery.min.js"></script>
    <script>
        function register() {
            var reg_info = {
                name: document.getElementById("username").value,
                passwd: document.getElementById("password").value
            };
            
            $.ajax({
                url: "/register",
                type: "POST",
                data: JSON.stringify(reg_info),
                success: function (res) {
                    alert(res.result);
                    window.location.assign("/login.html");
                },
                error: function (xhr) {
                    document.getElementById("username").value = "";
                    document.getElementById("password").value = "";
                    alert(xhr.responseJSON.result);
                }
            })
        }
        
        // 按回车键注册
        document.getElementById("password").addEventListener("keypress", function(event) {
            if (event.key === "Enter") {
                register();
            }
        });
    </script>
</body>
</html>